from database_connection.index import Base, engine
from sqlalchemy import Text, Column, Integer, String


class Mail(Base):  # 必须继承declaraive_base得到的那个基类
    __tablename__ = "Mail"  # 必须要有__tablename__来指出这个类对应什么表，这个表可以暂时在库中不存在，SQLAlchemy会帮我们创建这个表
    id = Column(Integer, nullable=False, primary_key=True, autoincrement=True, unique=True, comment="id")
    mail = Column(String(255, collation="utf8_bin"), nullable=False)  # 邮箱号
    code = Column(Text, nullable=False)  # 验证码
    start_time = Column(Text, nullable=False)  # 起始时间

    def mail_to_dict(self):
        return {
            'id': self.id,
            'mail': self.mail,
            'code': self.code,
            'start_time': self.start_time
        }

    def __init__(self, mail, code, start_time):
        self.mail = mail
        self.code = code
        self.start_time = start_time


Base.metadata.create_all(engine)
